package com.rams.jhms.gui.datamodels;

import java.util.List;

import javax.swing.AbstractListModel;
import javax.swing.ListModel;
import javax.swing.event.ListDataListener;

import com.rams.jhms.dao.DerbyArtistDAO;
import com.rams.jhms.dto.ArtistDTO;

public class ArtistListModel extends AbstractListModel implements ListModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8447173913749026811L;
	
	private DerbyArtistDAO dao = new DerbyArtistDAO();
	private List<ArtistDTO> artList = dao.getArtistsList();

	public int getSize() {
		return artList.size();
	}

	public Object getElementAt(int index) {
		return artList.get(index);
	}

	public void addElement(ArtistDTO art) {
		artList.add(art);
		dao.addAtrist(art); // TODO: must return added state
		fireContentsChanged(this, artList.size()-1, artList.size()-1);
	}
	
	public void addListDataListener(ListDataListener l) {

	}

	public void removeListDataListener(ListDataListener l) {

	}

	public void setArtistFilter(String filter) {
		artList = dao.findArtistByName(filter);
		fireContentsChanged(this, 0, artList.size()-1);
	}
}
